<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/common.css" media="all">
    <link rel="stylesheet" href="../viewstyle/css/searchform.css">
    <script src="/js/layui/layui.all.js"></script>
    <script src="/admin/js/token.js"></script>
    <script src="../viewstyle/config/config2.js"></script>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div style="text-align: center;">
                <div class="layui-inline">
                    <input class="layui-input" name="id" id="test-table-demoReload" placeholder="输入昵称或账号"
                           autocomplete="off">
                </div>

                <div class="layui-inline">
                    <button id="btnsearch" class="layui-btn layuiadmin-btn-admin" lay-submit
                            lay-filter="LAY-user-back-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>搜索
                    </button>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <button class="layui-btn layui-btn-sm layui-icon layui-icon-add-circle" lay-event="addadminuser"
                    id="addadminuser">新增子用户
            </button>
            <table class="layui-hide" id="t" lay-filter="t"></table>
        </div>
    </div>
</div>

</body>

<script type="text/html" id="tb">

    <div class="layui-container">
        <span class="">用户列表</span>
    </div>
</script>

<script type="text/html" id="caozuo">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">详情编辑</a>
    <a class="layui-btn layui-btn-xs" lay-event="chonzhi">充值</a>
</script>

<script>


        var $ = layui.$;
        var form = layui.form;
        var table = layui.table;
        var x = layui.data("treeadminid").adminid;
        var adminId=null;
        if(typeof(x)=="undefined"){
            adminId = localStorage.getItem("admin_id");
        }else{
            adminId = x;
        }
        table.render({
            elem: '#t',
            id: 'mytable',
            toolbar: '#tb',
            url: '/admin/searchyhgl?adminId='+adminId,
            cols: [
                [{
                    field: 'admin_name',
                    title: '昵称',
                    width: '13%',
                    align: 'center'
                },
                    {
                        field: 'admin_phone',
                        title: '账号',
                        width: '11%',
                        align: 'center'
                    },
                    {
                        field: 'admin_type',
                        title: '用户性质',
                        width: '10%',
                        align: 'center'
                    },
                    {
                        field: 'admin_money',
                        title: '沃币',
                        width: '10%',
                        align: 'center'
                    },
                    {
                        field: 'admin_person_in_charge',
                        title: '负责人',
                        align: 'center'
                    },
                    {
                        field: 'admin_last_login_time',
                        title: '最近登录时间',
                        align: 'center'

                    },
                    {
                        title: '操作',
                        align: 'center',
                        toolbar: '#caozuo',
                        fixed: 'right'
                    }
                ]
            ],
            page: true
        });

        layui.data('treeadminid', {
            key: 'adminid'
            ,remove: true
        });

        //搜索
        $("#btnsearch").click(
            function () {
                        table.reload('mytable', {
                            where: {
                                adminName: $('#test-table-demoReload').val(),
                                adminPhone: $('#test-table-demoReload').val()
                            }
                            ,
                            page: {
                                curr: 1
                            }
                        });

            })
        var wenzi = layui.data("wenzi").adminName;
        if(typeof(wenzi)=="undefined") {
            $("#btnsearch").click();
        }else{
            $("#test-table-demoReload").val(wenzi)
            $("#btnsearch").click();
        }
        layui.data('wenzi', {
            key: 'adminName'
            ,remove: true
        });


        //键盘回车监听
        $(window).keypress(function (event) {
            if (event.which === 13) {
                $('#btnsearch').click();
            }
        })

        //操作加事件
        table.on('tool(t)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            var tr = obj.tr;

            switch (layEvent) {
                case "edit":
                    layui.data("xiugai", {key: "admindata", value: data});
                    layer.open({
                        type: 2,
                        content: 'Xiugaiadmin.html',
                        area: ['100%', '100%'],
                        title: '修改用户信息',
                        end: function () {
                            $(".layui-laypage-btn").click();
                        }
                    });
                    break;
                case "chonzhi":
                    layui.data("smonery", {key: "adminmonery", value: data});
                    layer.open({
                        type: 2,
                        content: 'chongzhi.html',
                        area: ['100%', '100%'],
                        title: '充值沃币',
                        end: function () {
                            $(".layui-laypage-btn").click();
                        }
                    });
                    break;
            }
        });

        //新增子用户
        $("#addadminuser").click(function (obj) {
            layer.open({
                type: 2,
                content: 'addadminuser.html',
                area: ['100%', '100%'],
                title: '新增子用户',
                end: function () {
                    $(".layui-laypage-btn").click();
                }
            });
        });




</script>
</html>
